<template>
  <div>
       <el-table
      :data="specsList"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="规格编号"> </el-table-column>
      <el-table-column prop="specsname" label="规格名称"> </el-table-column>
      <el-table-column prop="attrs" label="规格属性"> </el-table-column>
      <!-- <template slot-scope="scope">
        <div>
          <el-tag v-for="(item,index) in scope.row.attrs" :key="index"></el-tag>
        </div>
      </template> -->
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="primary" v-if="scope.row.status == 1"
              >启 用</el-button
            >
            <el-button type="success" v-else>禁 用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div>
            <el-button type="info" @click="edit(scope.row.id)">编 辑</el-button> 
              <v-del @del="del(scope.row.id)"></v-del>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="prev, pager, next" :total="specsCount" :page-size="specsSize" @current-change="changePage">
    </el-pagination>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { specsDel } from "../../../request/api";
import { successAlert, warningAlert } from "../../../utils/alert";
export default {
  props: [],
  components: {},
  data() {
    return {
    };
  },
  computed: {
    ...mapGetters({
      specsList:"specs/list",
      specsCount:"specs/count",
      specsSize:"specs/size"

    }),
  },
  methods: {
    ...mapActions({
      asyncSpecsList:"specs/asyncList",
      asyncSpecsCount:"specs/asyncCount",
      asyncSpecsPage:"specs/asyncPage"
    }),
    edit(id) {
      // 通知父组件，我点了编辑
      this.$emit("edit", id);
    },
  del(id) {
     specsDel({id:id }).then((res) => {
        if (res.data.code == 200) {
          // 成功的提示窗
          successAlert(res.data.msg);
          // 刷新列表数据
          this.asyncSpecsList();
          // 重新请求列表总数
         this.asyncSpecsCount()
        } else {
          // 失败的提示窗
          warningAlert(res.data.msg);
        }
      });
    },

    // 当分页中的当前页码发生改变
    changePage(num){
      this.asyncSpecsPage(num)
    }
  },
  mounted() {
    this.asyncSpecsPage(1)

    this.asyncSpecsCount()
  },
};
</script>
<style scoped>
</style>